package com.carpedil.mq.client;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.messaging.handler.annotation.Header;

import java.io.IOException;

/** @author Administrator */
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class MqClientMain {
  public static void main(String[] args) {
    SpringApplication.run(MqClientMain.class, args);
  }

  @RabbitListener(queues = "one")
  public void getMqQueue1(String str, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
    System.out.println(str);
    try {
      // tag--队列的标记 ，false-->不批量处理
      channel.basicAck(tag, false);
      // tag--队列的标记 ，false-->不批量处理  true-->不消费（队列数据还存在）
      //      channel.basicNack(tag, false, true);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  @RabbitListener(queues = "two")
  public void getMqQueue2(String str) {
    System.out.println(str);
  }

  @RabbitListener(queues = "three")
  public void getMqQueue3(String str) {
    System.out.println(str);
  }

  @RabbitListener(queues = "four")
  public void getMqQueue4(String str) {
    System.out.println(str);
  }
}
